package com.yumeko.springcloud.service.impl;

import com.yumeko.springcloud.entity.TPayment;
import com.yumeko.springcloud.dao.TPaymentDao;
import com.yumeko.springcloud.service.TPaymentService;
import com.yumeko.springcloud.util.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TPayment)表服务实现类
 *
 * @author Zheng Hao
 * @since 2020-03-07 03:02:21
 */
@Service("tPaymentService")
@Slf4j
public class TPaymentServiceImpl implements TPaymentService {
    @Resource
    private TPaymentDao tPaymentDao;

    @Value("${server.port}")
    private String serverPort;
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ResponseData<TPayment> queryById(Long id) {
        TPayment tPayment = tPaymentDao.queryById(id);
        if (tPayment!=null){
            log.info("true");
            return new ResponseData(200,"true,server-port="+serverPort,tPayment);
        }else {
            log.error("false");
            return new ResponseData(500,"false,server-port="+serverPort);
        }
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<TPayment> queryAllByLimit(int offset, int limit) {
        return this.tPaymentDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param tPayment 实例对象
     * @return 实例对象
     */
    @Override
    public ResponseData insert(TPayment tPayment) {
        int result = this.tPaymentDao.insert(tPayment);
        if (result>0){
            log.info("true");
            return new ResponseData(200,"true,server-port="+serverPort,result);
        }else {
            log.error("false");
            return new ResponseData(500,"false,server-port="+serverPort,result);
        }
    }

    /**
     * 修改数据
     *
     * @param tPayment 实例对象
     * @return 实例对象
     */
    @Override
    public ResponseData<TPayment> update(TPayment tPayment) {
        int i = this.tPaymentDao.update(tPayment);
        return this.queryById(tPayment.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.tPaymentDao.deleteById(id) > 0;
    }
}